--
-- PostgreSQL database dump
--

SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- Name: WEB_GALLERY_DEV; Type: DATABASE; Schema: -; Owner: -
--

CREATE DATABASE "WEB_GALLERY_DEV" WITH TEMPLATE = template0 ENCODING = 'UTF8';


\connect "WEB_GALLERY_DEV"

SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: -
--

CREATE PROCEDURAL LANGUAGE plpgsql;


SET search_path = public, pg_catalog;

--
-- Name: update_record_timestamp(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION update_record_timestamp() RETURNS trigger
    AS $$
    BEGIN

        -- Remember who changed the payroll when
        NEW.d_updated := current_timestamp;
        RETURN NEW;
    END;
$$
    LANGUAGE plpgsql;


--
-- Name: hibernate_sequence; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE hibernate_sequence
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


--
-- Name: hibernate_sequence; Type: SEQUENCE SET; Schema: public; Owner: -
--

SELECT pg_catalog.setval('hibernate_sequence', 111, true);


SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: ta_reg_req; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE ta_reg_req (
    k_reg_req integer NOT NULL,
    c_code character varying(20),
    d_reg_req timestamp without time zone,
    f_user character varying(30)
);


--
-- Name: ta_user; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE ta_user (
    k_user character varying(30) NOT NULL,
    b_admin boolean,
    c_email character varying(255),
    c_password character varying(20),
    c_username character varying(60),
    c_updater character varying(30),
    d_updated timestamp without time zone,
    c_lang character varying(10),
    e_status integer
);


--
-- Name: tp_advert; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE tp_advert (
    k_advert bigint NOT NULL,
    c_text character varying(200),
    d_updated timestamp without time zone,
    c_updater character varying(30),
    f_target bigint
);


--
-- Name: tp_advert_clients; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE tp_advert_clients (
    fk_advert bigint NOT NULL,
    fk_user character varying(30) NOT NULL
);


--
-- Name: tp_gallery; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE tp_gallery (
    k_gallery bigint NOT NULL,
    c_description character varying(200),
    c_name character varying(60) NOT NULL,
    f_user character varying(30),
    f_parent bigint,
    d_updated timestamp without time zone,
    c_updater character varying(30),
    b_public boolean DEFAULT false
);


--
-- Name: tp_image; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE tp_image (
    k_image bigint NOT NULL,
    c_name character varying(60),
    n_size bigint,
    f_parent bigint,
    c_type character varying(40),
    d_updated timestamp without time zone,
    c_updater character varying(30)
);


--
-- Data for Name: ta_reg_req; Type: TABLE DATA; Schema: public; Owner: -
--

COPY ta_reg_req (k_reg_req, c_code, d_reg_req, f_user) FROM stdin;
\.


--
-- Data for Name: ta_user; Type: TABLE DATA; Schema: public; Owner: -
--

COPY ta_user (k_user, b_admin, c_email, c_password, c_username, c_updater, d_updated, c_lang, e_status) FROM stdin;
admin	t	admin@webgallery.com	admin	System Administrator	admin	2007-12-13 15:25:17.459	ro	\N
\.


--
-- Data for Name: tp_advert; Type: TABLE DATA; Schema: public; Owner: -
--

COPY tp_advert (k_advert, c_text, d_updated, c_updater, f_target) FROM stdin;
\.


--
-- Data for Name: tp_advert_clients; Type: TABLE DATA; Schema: public; Owner: -
--

COPY tp_advert_clients (fk_advert, fk_user) FROM stdin;
\.


--
-- Data for Name: tp_gallery; Type: TABLE DATA; Schema: public; Owner: -
--

COPY tp_gallery (k_gallery, c_description, c_name, f_user, f_parent, d_updated, c_updater, b_public) FROM stdin;
110	111	111	admin	\N	\N	admin	f
111	22222	22222	admin	110	\N	admin	f
\.


--
-- Data for Name: tp_image; Type: TABLE DATA; Schema: public; Owner: -
--

COPY tp_image (k_image, c_name, n_size, f_parent, c_type, d_updated, c_updater) FROM stdin;
\.


--
-- Name: ta_reg_req_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY ta_reg_req
    ADD CONSTRAINT ta_reg_req_pkey PRIMARY KEY (k_reg_req);


--
-- Name: ta_user_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY ta_user
    ADD CONSTRAINT ta_user_pkey PRIMARY KEY (k_user);


--
-- Name: tp_advert_clients_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY tp_advert_clients
    ADD CONSTRAINT tp_advert_clients_pkey PRIMARY KEY (fk_advert, fk_user);


--
-- Name: tp_advert_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY tp_advert
    ADD CONSTRAINT tp_advert_pkey PRIMARY KEY (k_advert);


--
-- Name: tp_gallery_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY tp_gallery
    ADD CONSTRAINT tp_gallery_pkey PRIMARY KEY (k_gallery);


--
-- Name: tp_image_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY tp_image
    ADD CONSTRAINT tp_image_pkey PRIMARY KEY (k_image);


--
-- Name: tp_gallery_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX tp_gallery_idx ON tp_gallery USING btree (f_user, c_name);


--
-- Name: trg_adv_clt_ts; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER trg_adv_clt_ts
    AFTER INSERT OR UPDATE ON tp_advert_clients
    FOR EACH ROW
    EXECUTE PROCEDURE update_record_timestamp();


--
-- Name: trg_adv_ts; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER trg_adv_ts
    AFTER INSERT OR UPDATE ON tp_advert
    FOR EACH ROW
    EXECUTE PROCEDURE update_record_timestamp();


--
-- Name: trg_gallery_ts; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER trg_gallery_ts
    AFTER INSERT OR UPDATE ON tp_gallery
    FOR EACH ROW
    EXECUTE PROCEDURE update_record_timestamp();


--
-- Name: trg_image_ts; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER trg_image_ts
    AFTER INSERT OR UPDATE ON tp_image
    FOR EACH ROW
    EXECUTE PROCEDURE update_record_timestamp();


--
-- Name: trg_reg_req_ts; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER trg_reg_req_ts
    AFTER INSERT OR UPDATE ON ta_reg_req
    FOR EACH ROW
    EXECUTE PROCEDURE update_record_timestamp();


--
-- Name: trg_user_ts; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER trg_user_ts
    AFTER INSERT OR UPDATE ON ta_user
    FOR EACH ROW
    EXECUTE PROCEDURE update_record_timestamp();


--
-- Name: fk2923786f3573594c; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY tp_gallery
    ADD CONSTRAINT fk2923786f3573594c FOREIGN KEY (f_parent) REFERENCES tp_gallery(k_gallery) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk2923786fcd117bd8; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY tp_gallery
    ADD CONSTRAINT fk2923786fcd117bd8 FOREIGN KEY (f_user) REFERENCES ta_user(k_user) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk3113d2f73c46c233; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY tp_advert
    ADD CONSTRAINT fk3113d2f73c46c233 FOREIGN KEY (f_target) REFERENCES tp_gallery(k_gallery);


--
-- Name: fk441a51b83573594c; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY tp_image
    ADD CONSTRAINT fk441a51b83573594c FOREIGN KEY (f_parent) REFERENCES tp_gallery(k_gallery) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk89cfa4a0a372962b; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY tp_advert_clients
    ADD CONSTRAINT fk89cfa4a0a372962b FOREIGN KEY (fk_advert) REFERENCES tp_advert(k_advert);


--
-- Name: fk89cfa4a0e95552d9; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY tp_advert_clients
    ADD CONSTRAINT fk89cfa4a0e95552d9 FOREIGN KEY (fk_user) REFERENCES ta_user(k_user) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk_adv_cln; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY tp_advert_clients
    ADD CONSTRAINT fk_adv_cln FOREIGN KEY (fk_advert) REFERENCES tp_advert(k_advert) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk_adv_gal; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY tp_advert
    ADD CONSTRAINT fk_adv_gal FOREIGN KEY (f_target) REFERENCES tp_gallery(k_gallery);


--
-- Name: fkc59b4261cd117bd8; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ta_reg_req
    ADD CONSTRAINT fkc59b4261cd117bd8 FOREIGN KEY (f_user) REFERENCES ta_user(k_user) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: public; Type: ACL; Schema: -; Owner: -
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


--
-- PostgreSQL database dump complete
--

